/* Author: 
	Eric Mantoani <eu@eric.com.br>
*/


(function($){

	$(document).ready(function(){
		Eleazar.load();
	});
	
	Eleazar = {
		ui: {
			
			init: function() {
				
			},
		
			section: {
				
				inscricao: {
					init: function(){
						var form = $('#inscricao-festival');
						
						form.find('input[name="nascimento"]').mask('99/99/9999');
						
						form.validate({
							submitHandler: function(e){
								e.preventDefault(); e.stopPropagation();
							},
							
							rules: {
								nome: {
									required: true,
									minlength: 3,
									maxlength: 4
								},
								email: {
									required: true,
									email: true
								},
								nascimento: {
									required:true,
									date: true
								},
								cidade: {
									required: true
								},
								rg: {
									required: true
								},
								documento: {
									required: true
								},
								instrumento: {
									required: true
								},
								'classificacao-vocal': {
									required: function(element){
										return $("#instrumento").val() === 'voz';
									}
								},
								concordo: {
									required: true
								}
							
							},
							
							messages: {
								nome: {
									required: i18n.name.required,
									minlength: i18n.name.minlength,
									maxlength: i18n.name.maxlength
								},
								email: {
									required: i18n.email.required,
									email: i18n.email.required
								},
								nascimento: {
									required: i18n.nascimento.required,
									date: i18n.nascimento.date
								},
								cidade: {
									required: i18n.cidade.required
								},
								rg: {
									required: i18n.rg.required
								},
								documento: {
									required: i18n.documento.required
								},
								instrumento: {
									required: i18n.instrumento.required
								},
								'classificacao-vocal': {
									required: i18n.classificacaoVocal.required
								},
								concordo: {
									required: i18n.concordo.required
								}
							}
							
						});
						
						
					}
					
				}
			}	
		
		},
		
		utils: {
			getSection: function(section) {
				var sectionId = typeof section!= 'undefined' && $(document.getElementById(section)).length>0? $(document.getElementById(section)).attr('id') : document.body.id;
				return sectionId.replace(/\-([a-z])/g,function(){ // transforms id into method name
					return arguments[1].toUpperCase();
				});
			},
			
			getParam: function(){
				var search = window.location.search,
					arrParam = search.replace("?","").split("&"),
					json = {},
					param;
	
				for(i in arrParam){
					param = arrParam[i].split("=");
				    if(param.length > 1) json[param[0]] = param[1];
				}
	
				return json;
			}
		},
		
		load: function() {
			this.ui.init();
			try {			
				this.ui.section[this.utils.getSection()].init(); // from body.id
			} catch(err) {
				//alert(err.toString()); // debug
				//console.dir(err); // debug
			}
		},
	}
	
})(jQuery);